package com.baidu.servlet.controller;

import java.net.UnknownHostException;
import java.util.Iterator;
import java.util.List;

import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;

import org.springframework.data.mongodb.core.MongoOperations;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.core.SimpleMongoDbFactory;

import com.mongodb.DB;
import com.mongodb.Mongo;

public class MongoServlet extends HttpServlet {

	@Override
	public void init(ServletConfig config) throws ServletException {
		
		MongoOperations mongoTemplate=null;
		try {
			
			mongoTemplate = new MongoTemplate(new SimpleMongoDbFactory(new Mongo("localhost", 27017), "mydb"));
			/*List<Img> findAll = mongoTemplate.findAll(Img.class ,"images");
	      	Iterator<Img> it = findAll.iterator();
			while (it.hasNext()) {
				Img img = (Img) it.next();
				System.out.println(img);
			}*/
			
		} catch (UnknownHostException e) {
			e.printStackTrace();
		}
		
		
		config.getServletContext().setAttribute("aa", "aa");
	}
	


	
	

}
